; Draws the menus for upgrading, refueling, exchanging, etc.


; HL is the menu to draw

Draw_Icon_Menu:

 ld a, (hl)  	;HL points to the menu to draw.  The first byte of the menu
		;is either a 1 or a 0.  0 means draw a 3x3 menu, 1 means
		;draw a soft key menu.  A soft key menu is a 1 x something menu
		;at the bottom of the screen.

 push hl	;Saves the location of the menu to draw
 
;ld e,a		;Register E is used when one menu can lead to another menu.  For example,
		;when choosing a structure to build, you can choose to display a menu to
		;allow you to build advanced structures
 

 or a		;Register A = 0 means that the menu is a 3 x 3 menu

 jr z, Draw_3x3_Menu
 
Draw_Soft_Key_Menu:

Draw_3x3_Menu:

;Set the location of the menu cursor

 ld a, 16
 ld (TagX), a
 ld a, 33
 ld (TagY), a

;Draws the menu, not the cursor.

 ld a, 6
 ld (Sprite_Width),a
 ld b, 48
 xor a
 
 push hl
 pop ix
 
 ld de,37	;In a 3 x 3 menu, there is 18 words of data for text and routines
		;to jump to, and one byte specifying that the menu is indeed a 3x3
		;menu.  37 bytes total to skip to get to the actual sprite data.


 add ix, de	;ix now points to the sprite data

 
 ld l, 16
 call Put_Sprite_Overwrite


Draw_Icon_Menu_Cursor:

 ld a,2
 ld (Sprite_Width),a
 ld b,15
 ld a, (TagY)
 ld l, a
 ld a, (TagX)
 ld ix, Icon_Menu_Cursor

 

 call Put_Sprite_XOR

 ld hl, plotsscreen

 call safecopy

;CHECK TO SEE IF POP HL CAN BE DELETED


 pop hl		;Popping this value and pushing it again fixes an error
		;with the stack pointer

 call Draw_Item_Description	;Displays text that tells what the particular
				;option does
 push hl

 ld a,2				;Displays the cursor
 ld (Sprite_Width),a
 ld b,15
 ld a, (TagY)
 ld l, a
 ld a, (TagX)
 ld ix, Icon_Menu_Cursor
 call Put_Sprite_XOR

Icon_Menu_Get_Key:


 B_CALL _GetCSC ;Makes absolutely sure that the player has released the
		 ;key so as to avoid accidental key holds

 or a		;If no key was pressed, we want to continue searching for a keypress

 jr z, Icon_Menu_Get_Key



 ld d, Icon_Menu	;Register D is used to determine the context whenever a key
			;is pressed.  This way, one key can have several purposes
			;depending on if a player wants to attack, build, or even
			;simply move.
 
 ld e, 0		;We let Register E be equal to 0.  If E remains 0, it is not time
			;to leave the menu yet.  In other words, if E remains 0, the player
			;only pressed up, down, left or right.


;Check to see if this can be fixed
 pop hl
 
 call Context_Sensitive_Get_Key

 push hl

 ld a, e

 or a
 jp z, Draw_Icon_Menu_Cursor

 
 

Do_Menu_Operation:

 pop hl
 ld b,0
 
 

 inc hl
 
 
 add hl, bc
 ld e, (hl)
 inc hl
 ld d, (hl)
 ex de, hl
 push hl
 
 ld hl, plotsscreen
 call safecopy

 pop hl
 jp (hl)

Do_Menu_Operation_Return:
 
 ret








Icon_Menu_Cursor:

	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
	.db %11111111,%11111110
